'use strict'

 const { DataTypes, Model, Op } = require('../../azeroth').sequelize;
 const schedule = require('node-schedule');
const {
    linedb_cf_jingdujiance_config,
} = require('../config.json').line_db; // 目标库

// sequlize 实例
const seq_aim_cf_jingdu = require('../lib/db').getSequelizeInstance(linedb_cf_jingdujiance_config);


class PanelInfo extends Model { }

PanelInfo.init(
    {
        uid: {
            field: 'uid',
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true
        },
        job_id: {
            field: 'job_id',
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true,
            autoIncrement: false
        },
        panel_id: {
            field: 'panel_id',
            type: DataTypes.STRING
        },
        flaw_count: {
            field: 'flaw_count',
            type: DataTypes.INTEGER
        },
        is_ok: {
            field: 'is_ok',
            type: DataTypes.INTEGER
        },
        length_md: {
            field: 'length_md',
            type: DataTypes.INTEGER
        },
        length_cd: {
            field: 'length_cd',
            type: DataTypes.INTEGER
        },
        save_path: {
            field: 'save_path',
            type: DataTypes.STRING
        },
        gen_time: {
            field: 'gen_time',
            type: DataTypes.BIGINT
        },
        gen_time_str: {
            field: 'gen_time_str',
            type: DataTypes.STRING
        },
        detectParam: {
            field: 'detectParam',
            type: DataTypes.TEXT
        },
        checked: {
            field: 'checked',
            type: DataTypes.INTEGER
        },
    },
    {
        freezeTableName: true,
        sequelize: seq_aim_cf_jingdu,
        modelName: 'panel',
        timestamps: false
    }
)

  PanelInfo.uploadPanelInfo = async (data) => {
     let res = await PanelInfo.bulkCreate(data, {updateOnDuplicate: ['uid', 'panel_id', 'job_id', 'flaw_count', 'is_ok', 'length_md', 'length_cd', 'gen_time', 'gen_time_str', 'checked']});
     return res;
 }

 module.exports = {
     PanelInfo
 };